package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.common.entity.Discount;

import java.util.List;

@Mapper
public interface DiscountMapper {

    // 插入一条折扣记录
    @Insert("INSERT INTO discount (name, type, value, min_amount, max_amount, start_time, end_time, status, created_by, updated_by) " +
            "VALUES (#{name}, #{type}, #{value}, #{minAmount}, #{maxAmount}, #{startTime}, #{endTime}, #{status}, #{createdBy}, #{updatedBy})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Discount discount);

    // 根据 ID 更新折扣记录
    @Update("UPDATE discount SET name = #{name}, type = #{type}, value = #{value}, min_amount = #{minAmount}, max_amount = #{maxAmount}, " +
            "start_time = #{startTime}, end_time = #{endTime}, status = #{status}, updated_by = #{updatedBy} " +
            "WHERE id = #{id}")
    int updateById(Discount discount);

    // 根据 ID 删除折扣记录
    @Delete("DELETE FROM discount WHERE id = #{id}")
    int deleteById(Long id);

    // 根据 ID 查询折扣记录
    @Select("SELECT * FROM discount WHERE id = #{id}")
    Discount selectById(Long id);

    // 查询所有折扣记录
    @Select("SELECT * FROM discount")
    List<Discount> selectAll();
}